
for k,v in pairs(load_excel('物品数据.xlsx','炮台')) do
    local name = k
    v.tip = ('%s|n%s'):format(v['介绍'],v['效果'])
    v.is_shop = true
    v.show_num = 0
    v.empty_item = true

    v.title = [['name'('show_num'/'上限等级') ]]
    ac.lni('skill',k,v)

    local mt = ac.skill[name]

    function mt:get_gold()
        return self['消耗金币'] + self.show_num * (self['递增'] or 0)
    end

    function mt:on_sell(hero,player)
        local unit = self.owner
        local name = self.name
        self.show_num = self.show_num + 1
        if self.show_num>=self['上限等级'] then
            self:set_enable(false)
        end
        show_skill_tip(player,self.slotid,'成功')
        unit:set_data(name,self.show_num * self.data1)
    end
end




local excel = load_excel('捕鱼设定.xlsx','炮台参数')
local data = excel['捕鱼炮台']


local mt = ac.skill['打鱼']
mt.targettype = '点'
mt.range = 2800
mt.speed = data['默认速度'] or 1800
mt.area = data['默认范围'] or 150
mt.cool = data['开火间隔'] or 0
mt.add_shot = data['默认效率'] or 0
mt.slotid = 1
mt.model1 = [[Abilities\Spells\Orc\Ensnare\EnsnareMissile.mdl]]
mt.model1 = [[Hero_Gyrocopter_N5_F_Missile.mdl]]
mt.count = 0

function mt:on_cast_shot()
    if self.count<=0 then
        return
    end
    local hero = self.owner
    local target = self.target
    local point1 = hero:get_point()
    local point2 = target:get_point()
    local angle = point1 / point2
    local area = self.area + hero:get_data('升级范围',0)
    local speed = self.speed + hero:get_data('升级速度',0)
    local mover = point1:launch_wave(self.model1,angle,speed,self.range,3,50)
    hero:set_facing(angle)
    sc.loopUnit(0.03,mover,area*0.8,function(sc,unit)
        if unit:is_type('鱼') then
            mover:finish()
        end
    end):can_god()

    function mover.on_finish(mover)
        local point = mover.mover:get_point()
        local group = ac.selector('unit'):range(point,area):is_type('鱼'):can_god():get()
        point:effect{
            model = [[Abilities\Spells\Orc\Ensnare\ensnareTarget.mdl]],
            size = area/75,
            time = 0.2,
        }
        for _,unit in ipairs(group) do
            hero:notify('炮台-捕捉到鱼',hero,unit,hero:get_data('升级威力',0))
        end
    end
    
    self.count = self.count - 1
    hero.ui_title = ('剩余炮弹：%0.f'):format(self.count)
end

function mt:on_add()
    local hero = self.owner
    local player = hero.owner
    local time = 10
    hero:set('生命上限',time)
    hero:set('生命',0.1)
    hero.ui_title = ('剩余炮弹：%0.f'):format(self.count)
    hero.work_timer = ac.loop(time*1000,function()
        self.count = self.count + self.add_shot + hero:get_data('升级效率',0)
        hero.ui_title = ('剩余炮弹：%0.f'):format(self.count)
        hero:set('生命',0.1)
    end)
    shop_add_panel(hero)
    self:gc(hero.work_timer)
    self:gc(ac.loop(10,function()
        hero:add('生命',0.01)
    end))
    self:gc(ac.loop(self.cool*1000,function()
        if hero:get_data('自动打鱼开关') and self.count>0 then
            local point = hero:get_point()
            local unit = ac.selector('unit'):range(point,self.range-500):is_type('鱼'):near(point):can_god():first()
            if unit then
                local last = unit:get_point()
                local area = point * last
                local target = last - {unit:get_facing(),area/self.speed * unit:get('移动速度')+50}
                self:cast(target)
            end
        end
    end))
    self:gc(player:event '玩家-添加炮弹'(function(_,player,num)
        self.count = self.count + num
        hero.ui_title = ('剩余炮弹：%0.f'):format(self.count)
    end))
end


local mt = ac.skill['自动打鱼']
mt.art1 = [[图标\自动.blp]]
mt.art2 = [[图标\手动.blp]]
mt.cool = 1

function mt:on_add()
    self:on_cast_shot()
end
function mt:on_cast_shot()
    local unit = self.owner
    local open = not unit:get_data('自动打鱼开关')
    unit:set_data('自动打鱼开关',open)
    if open then
        self:set_art(self.art1)
        self.tip = [[点击关闭自动打鱼]]
    else
        self:set_art(self.art2)
        self.tip = [[点击开启自动打鱼]]
    end
end